<template>
  <div class="loanAll">
    <search-page :search="search" :init="true" :copysearch="copysearch" @selectChange="searchSelectChange" @searchdata="getdata">
    </search-page>
    <div class="tableBox">
      <div class="btnBox" style="margin-bottom: 10px">
        <el-button class="btn" type="primary" @click="addBtn('add')">新建</el-button>
        <el-button class="btn" type="primary" @click="editBtn('edit')">修改</el-button>
        <el-button class="btn" type="primary" @click="delBtn">删除</el-button>
        <el-button class="btn" type="primary" @click="submitBtn">提交</el-button>
      </div>
      <simple-table  ref="multipleTable" :table="dataTable" @onHandleSelectionChange="handleSelectionChange">
        <template slot-scope="props" slot="rentCode">
          <span style="color:rgb(4, 51, 255);cursor:pointer;" @click="handelRenting(props.obj.row.rentCode)">{{props.obj.row.rentCode}}</span>
        </template>
        <template slot-scope="props" slot="status">
          <span>{{statusArr[props.obj.row.status]}}</span>
        </template>
        <template slot-scope="props" slot="approve">
          <p @click="handelCheck(props.obj.row.rentCode)"
             style="text-align: center;cursor: pointer;color: blue;font-weight: bold;">查看</p>
        </template>
      </simple-table>
      <pagination :pager="pager" @change="getPageData"></pagination>
    </div>
    <!--新建-->
    <public-model :publiconfig="publiconfigAdd">
      <template slot="public-model-content">
        <public-form ref="form" :formconfig="formconfigAdd" :ruleForm="ruleFormAdd" :rules="rulesAdd"
                     @selectChange="selectChange" @saveForm="saveForm"></public-form>
      </template>
      <template slot="model-footer">
        <el-button class="btn" type="primary" @click="saveBtn('save')">保 存</el-button>
        <el-button class="btn" type="primary" @click="saveBtn('submit')">提 交</el-button>
        <el-button class="btn" @click="publiconfigAdd.show =false">取 消</el-button>
      </template>
    </public-model>
    <!--修改，查看-->
    <public-model :publiconfig="publiconfigEdit">
      <template slot="public-model-content">
        <public-form ref="form2" :formconfig="formconfigEdit" :ruleForm="ruleFormEdit" :rules="rulesEdit"
                     @selectChange="selectChange" @saveForm="saveForm2"></public-form>
      </template>
      <template slot="model-footer" v-if="publiconfigEdit.title == '修改租房单'">
        <el-button class="btn" type="primary" @click="saveBtnEdit('edit')">{{publiconfigEdit.title}}保 存</el-button>
        <el-button class="btn" type="primary" @click="saveBtnEdit('submit')">提 交</el-button>
        <el-button class="btn" @click="publiconfigEdit.show =false">取 消</el-button>
      </template>
    </public-model>
    <!--查看审批历史-->
    <public-model :publiconfig="publiconfigCheck">
      <template slot="public-model-content">
        <simple-table :table="dataTable2">
        </simple-table>
      </template>
    </public-model>
  </div>
</template>

<script>
import {COMMON_API_PATH} from '../../../resource'
import {formatDate,attrChange,attrChange2} from "../../../tool/common";
export default {
  name: "project-renting",
  data() {
    var validateHousePersonnel = (rule, value, callback) => {
      if (!value) {
        callback(new Error('请输入'));
      } else if (!new RegExp("^[0-9][0-9]*$").test(value)) {
        callback(new Error('请输入大于或等于0的整数'));
      } else {
        callback();
      }
    };
    //校验日期，付款时间不能超过合同期限
    var validateDate = (rule, value, callback) => {
      if (!value) {
        callback(new Error('请输入'));
      }else if(rule.field == 'paymentTime' && parseInt(value[0].split("-").join(""))>parseInt(this.ruleFormAdd.contractTerm[1].split("-").join(""))){
        callback(new Error('付款时间不能超过合同期限'));
      }else if(rule.field == 'contractTerm' && parseInt(value[1].split("-").join(""))<parseInt(this.ruleFormAdd.paymentTime[0].split("-").join(""))){
        callback(new Error('合同期限应该在付款时间之前'));
      }else{
        callback();
      }
    };
    return {
      copysearch: {},
      search: [
        {
          name: "合同期限",
          key: "contractTerm",
          value: "",
          type: "daterange",
        },
        {
          name: "项目名称",
          key: "projectName",
          value: "",
          type: "select",
          event:'change',
          list: []
        },
        {
          name: "项目编号",
          key: "projectCode",
          value: "",
          type: "text",
          disabled:true
        },

      ],
      dataTable: {
        hasSelect: true, //是否有复选框
        tableShow: false, //是否显示表格
        hasOrder: false, //是否显示序号列
        height: "450px",
        tr: [
          // 表头数据
          {
            label: "租房申请单号",
            prop: "rentCode",
            minWidth: '160',
            show: "template"
          },
          {
            label: "项目名称",
            prop: "projectName",
            minWidth: '100'
          },
          {
            label: "项目编号",
            prop: "projectCode",
            minWidth: '100'
          },
          {
            label: "项目经理",
            prop: "pm",
            minWidth: '100'
          },
          {
            label: "负责人",
            prop: "principal",
            minWidth: '100'
          },
          {
            label: "借款人",
            prop: "borrower",
            minWidth: '100'
          },
          {
            label: "地区",
            prop: "city",
            minWidth: '100'
          },
          {
            label: "面积",
            prop: "houseType",
            minWidth: '100'
          },
          {
            label: "租房地址",
            prop: "houseAddress",
            minWidth: '150'
          },
          {
            label: "项目人员",
            prop: "projectCode",
            minWidth: '100'
          },
          {
            label: "合同期限",
            prop: "projectCode",
            minWidth: '200'
          },
          {
            label: "单据状态",
            prop: "status",
            minWidth: '150',
            show: "template"
          },
          {
            label: "审批明细",
            prop: "approve",
            minWidth: '100',
            show: "template"
          }
        ],
        data: [],
        border: true,
        hasOperation: false,
        operation: {
          label: "操作",
          width: "160",
          className: "",
          data: []
        }
      },
      statusArr: ['保存', '审批中', '驳回', '等待行政确认', '行政审批完成','销假申请中','撤销'],
      pager: {
        currentPage: 1,
        pageSize: 10,
        total: null,
        pageSizes: [5, 10, 50, 100]
      },
      publiconfigAdd: {
        title: "新建租房单",
        show: false,
        width:'960px',
        height: '400px'
      },
      formconfigAdd: [
        {
          label: "项目名称",
          prop: "projectName",
          type: "select",
          value: "",
          list: [],
          event:'change',
          formWidth: 'auto',
          labelWidth:"120px"
        },
        {
          label: "项目编号",
          prop: "projectCode",
          type: "text",
          value: "",
          disabled: true,
          formWidth: 'auto',
          labelWidth:"120px"
        },
        {
          label: "项目经理",
          prop: "pm",
          type: "text",
          value: "",
          disabled: true,
          formWidth: 'auto',
          labelWidth:"120px"
        },
        {
          label: "借款人",
          prop: "borrower",
          type: "text",
          value: "",
          formWidth: 'auto',
          labelWidth:"120px"
        },
        {
          label: "负责人",
          prop: "pm",
          type: "text",
          value: "",
          disabled: true,
          formWidth: 'auto',
          labelWidth:"120px"
        },
        {
          label: "城市",
          prop: "city",
          type: "text",
          value: "",
          formWidth: 'auto',
          labelWidth:"120px"
        },
        {
          label: "户型",
          prop: "houseType",
          type: "textarea",
          value: "",
          formWidth: '100%',
          width:'770px',
          labelWidth:"120px"
        },
        {
          label: "租房地址",
          prop: "houseAddress",
          type: "textarea",
          value: "",
          formWidth: '100%',
          width:'770px',
          labelWidth:"120px"
        },
        {
          label: "可入住人员(人数)",
          prop: "housePersonnel",
          type: "number",
          value: "",
          min:0,
          max:100000000,
          formWidth: '100%',
          width:'770px',
          labelWidth:"120px"
        },
        {
          label: "合同期限",
          prop: "contractTerm",
          type: "daterange",
          value: "",
          formWidth: '100%',
          width:'770px',
          labelWidth:"120px"
        },
        {
          label: "押金",
          prop: "deposit",
          type: "number",
          value: "",
          min:0,
          max:100000000,
          formWidth: 'auto',
          labelWidth:"120px"
        },
        {
          label: "月租",
          prop: "monthlyRent",
          type: "number",
          value: "",
          min:0,
          max:100000000,
          formWidth: 'auto',
          labelWidth:"120px"
        },
        {
          label: "付款周期",
          prop: "paymentCycle",
          type: "select",
          value: "",
          list: [
            {label:'季付',value:'季付'},
            {label:'月付',value:'月付'},
            {label:'半年付',value:'半年付'}
          ],
          formWidth: 'auto',
          labelWidth:"120px"
        },
        {
          label: "其他费用明细",
          prop: "otherFee",
          type: "number",
          value: "",
          min:0,
          max:100000000,
          formWidth: '100%',
          width:'770px',
          labelWidth:"120px"
        },
        {
          label: "预估年成本",
          prop: "annualCost",
          type: "number",
          value: "",
          min:0,
          max:100000000,
          formWidth: '100%',
          width:'770px',
          labelWidth:"120px"
        },
        {
          label: "申请宿舍物品",
          prop: "dormitoryItems",
          type: "textarea",
          value: "",
          formWidth: '100%',
          width:'770px',
          labelWidth:"120px"
        },
        {
          label: "付款时间",
          prop: "paymentTime",
          type: "daterange",
          value: "",
          formWidth: '100%',
          width:'770px',
          labelWidth:"120px"
        }
      ],
      ruleFormAdd: {},
      rulesAdd: {
        projectName: [
          {required: true, message: '请输入', trigger: ['blur', 'change']}
        ],
        borrower: [
          {required: true, message: '请输入', trigger: ['blur', 'change']}
        ],
        city: [
          {required: true, message: '请输入', trigger: ['blur', 'change']}
        ],
        houseType: [
          {required: true, message: '请输入', trigger: ['blur', 'change']}
        ],
        housePersonnel: [
          {validator:validateHousePersonnel, trigger: ['blur', 'change']}
        ],
        houseAddress: [
          {required: true, message: '请输入', trigger: ['blur', 'change']}
        ],
        contractTerm: [
          {required: true, message: '请输入', trigger: ['blur', 'change']},
          {validator:validateDate, trigger: ['blur', 'change']}
        ],
        deposit: [
          {required: true, message: '请输入', trigger: ['blur', 'change']}
        ],
        monthlyRent: [
          {required: true, message: '请输入', trigger: ['blur', 'change']}
        ],
        paymentTime: [
          {required: true, message: '请输入', trigger: ['blur', 'change']},
          {validator:validateDate, trigger: ['blur', 'change']}
        ]
      },
      publiconfigEdit: {
        title: "修改租房单",
        show: false,
        width:'960px',
        height: '400px'
      },
      formconfigEdit: [
        {
          label: "项目名称",
          prop: "projectName",
          type: "select",
          value: "",
          list: [],
          event:'change',
          formWidth: 'auto',
          labelWidth:"120px"
        },
        {
          label: "项目编号",
          prop: "projectCode",
          type: "text",
          value: "",
          disabled: true,
          formWidth: 'auto',
          labelWidth:"120px"
        },
        {
          label: "项目经理",
          prop: "pm",
          type: "text",
          value: "",
          disabled: true,
          formWidth: 'auto',
          labelWidth:"120px"
        },
        {
          label: "借款人",
          prop: "borrower",
          type: "text",
          value: "",
          formWidth: 'auto',
          labelWidth:"120px"
        },
        {
          label: "负责人",
          prop: "pm",
          type: "text",
          value: "",
          disabled: true,
          formWidth: 'auto',
          labelWidth:"120px"
        },
        {
          label: "城市",
          prop: "city",
          type: "text",
          value: "",
          formWidth: 'auto',
          labelWidth:"120px"
        },
        {
          label: "户型",
          prop: "houseType",
          type: "textarea",
          value: "",
          formWidth: '100%',
          width:'770px',
          labelWidth:"120px"
        },
        {
          label: "租房地址",
          prop: "houseAddress",
          type: "textarea",
          value: "",
          formWidth: '100%',
          width:'770px',
          labelWidth:"120px"
        },
        {
          label: "可入住人员(人数)",
          prop: "housePersonnel",
          type: "number",
          value: "",
          min:0,
          max:100000000,
          formWidth: '100%',
          width:'770px',
          labelWidth:"120px"
        },
        {
          label: "合同期限",
          prop: "contractTerm",
          type: "daterange",
          value: "",
          formWidth: '100%',
          width:'770px',
          labelWidth:"120px"
        },
        {
          label: "押金",
          prop: "deposit",
          type: "number",
          value: "",
          min:0,
          max:100000000,
          formWidth: 'auto',
          labelWidth:"120px"
        },
        {
          label: "月租",
          prop: "monthlyRent",
          type: "number",
          value: "",
          min:0,
          max:100000000,
          formWidth: 'auto',
          labelWidth:"120px"
        },
        {
          label: "付款周期",
          prop: "paymentCycle",
          type: "select",
          value: "",
          list: [
            {label:'季付',value:'季付'},
            {label:'月付',value:'月付'},
            {label:'半年付',value:'半年付'}
          ],
          formWidth: 'auto',
          labelWidth:"120px"
        },
        {
          label: "其他费用明细",
          prop: "otherFee",
          type: "number",
          value: "",
          min:0,
          max:100000000,
          formWidth: '100%',
          width:'770px',
          labelWidth:"120px"
        },
        {
          label: "预估年成本",
          prop: "annualCost",
          type: "number",
          value: "",
          min:0,
          max:100000000,
          formWidth: '100%',
          width:'770px',
          labelWidth:"120px"
        },
        {
          label: "申请宿舍物品",
          prop: "dormitoryItems",
          type: "textarea",
          value: "",
          formWidth: '100%',
          width:'770px',
          labelWidth:"120px"
        },
        {
          label: "付款时间",
          prop: "paymentTime",
          type: "daterange",
          value: "",
          formWidth: '100%',
          width:'770px',
          labelWidth:"120px"
        }
      ],
      ruleFormEdit:{},
      rulesEdit: {
        projectName: [
          {required: true, message: '请输入', trigger: ['blur', 'change']}
        ],
        borrower: [
          {required: true, message: '请输入', trigger: ['blur', 'change']}
        ],
        city: [
          {required: true, message: '请输入', trigger: ['blur', 'change']}
        ],
        houseType: [
          {required: true, message: '请输入', trigger: ['blur', 'change']}
        ],
        housePersonnel: [
          {validator:validateHousePersonnel, trigger: ['blur', 'change']}
        ],
        houseAddress: [
          {required: true, message: '请输入', trigger: ['blur', 'change']}
        ],
        contractTerm: [
          {required: true, message: '请输入', trigger: ['blur', 'change']},
          {validator:validateDate, trigger: ['blur', 'change']}
        ],
        deposit: [
          {required: true, message: '请输入', trigger: ['blur', 'change']}
        ],
        monthlyRent: [
          {required: true, message: '请输入', trigger: ['blur', 'change']}
        ],
        paymentTime: [
          {required: true, message: '请输入', trigger: ['blur', 'change']},
          {validator:validateDate, trigger: ['blur', 'change']}
        ]
      },
      userProject: {},
      clickedBtn:'save',
      isAddFlag:'add',
      seetableData: [
        //审批查看弹框数据
      ],
      multipleSelection: [],
      selectId: "",
      publiconfigCheck:{
        title: "审批明细",
        show: false,
        height: '200px'
      },
      dataTable2: {
        hasSelect: false, //是否有复选框
        tableShow: false, //是否显示表格
        hasOrder: true, //是否显示序号列
        height: "200px",
        tr: [
          // 表头数据
          {
            label: "审批人",
            prop:"approvalName",
            minWidth: '100',
          },
          {
            label: "审批建议",
            prop: "approvalOpinion",
            minWidth: '100'
          },
          {
            label: "驳回理由",
            prop: "rejectReason",
            minWidth: '100'
          },
          {
            label: "审批时间",
            prop: "approvalDate",
            minWidth: '100'
          }
        ],
        data: [],
        border: true,
        hasOperation: false,
        operation: {
          label: "操作",
          width: "160",
          className: "",
          data: []
        }
      }

    }
  },
  mounted() {
    this.getUserProject();
    this.getTableDatas();
  },
  components: {
  },
  methods: {
    //搜索栏下拉框改变时
    searchSelectChange(obj,val) {
      this.search[2].value = val[0].paraCode;
      this.$set(this.copysearch,'projectCode', val[0].paraCode);
      this.$set(this.copysearch,'projectName', val[0].paraKey);
    },
    //弹框中下拉改变时
    selectChange(obj){
      console.log('接受到的值')
      console.log(obj);
      if(this.isAddFlag == 'add'){
        let selectedProjectCode = this.ruleFormAdd[obj.item.prop];
        this.userProject.projectList.forEach((perProject) => {
          if(perProject.projectCode == selectedProjectCode){
            this.ruleFormAdd.projectName = perProject.projectName;
            this.ruleFormAdd.projectCode = perProject.projectCode;
            this.ruleFormAdd.pm = perProject.pm;
            this.ruleFormAdd.principal = perProject.pm;
          }
        })
      }else if(this.isAddFlag == 'edit'){
        let selectedProjectCode = this.ruleFormEdit[obj.item.prop];
        this.userProject.projectList.forEach((perProject) => {
          if(perProject.projectCode == selectedProjectCode){
            this.ruleFormEdit.projectName = perProject.projectName;
            this.ruleFormEdit.projectCode = perProject.projectCode;
            this.ruleFormEdit.pm = perProject.pm;
            this.ruleFormEdit.principal = perProject.pm;
          }
        })
      }



    },
    // 获取工号
    getUserNum() {
      return sessionStorage.getItem("RJ");
    },

    // 获取用户所有的项目信息
    getUserProject() {
      let self = this;
      let userNum = this.getUserNum();
      self.$http
        .get(`${COMMON_API_PATH}/userInfo/${userNum}`)
        .then(function (res) {
          let _data = res.data.userInfo;
          self.userProject = _data;
          //设置搜索栏项目名称
          this.search[1].list = attrChange(this.userProject.projectList,'projectCode','projectName');
        });
    },

    /*查询*/
    getdata(val) {
      console.log("查询");
      console.log(val);
      this.copysearch = val;
      this.getTableDatas()

    },
    getPageData(val) {
      console.log("分页")
      this.pager = val
      this.getTableDatas()

    },
    // 获取table 数据
    getTableDatas() {
      const {contractTerm} = this.copysearch
      const _contractTerm = contractTerm && contractTerm.length ? contractTerm : []
      let s=` 00:00:00`
      let d=` 23:59:59`
      if(_contractTerm.length>0){
        _contractTerm[0]= `${_contractTerm[0]}${s}`
        _contractTerm[1]= `${_contractTerm[1]}${d}`

      }
      let postParam = {
        "employeeNumber": this.userProject.employeeNumber,
        "contractEndDate":  _contractTerm[1] || '',
        "projectCode": this.copysearch.projectCode,
        "projectName": this.copysearch.projectName,
        "contractStartDate":  _contractTerm[0] || '',
        pageNumber: this.pager.currentPage,
        pageSize: this.pager.pageSize,
      };

      this.$http.post(`${COMMON_API_PATH}/rentAccount/queryAllByNumber`, postParam)
        .then(function (res) {
          if (res.data.statusCode == 1) {
            this.pager.total=res.data.item.total;
            this.dataTable.data= res.data.item.list;
          } else {
            this.$message({
              message: '请求失败',
              type: 'error'
            });
          }
        });

    },

    /*新建*/
    addBtn(val) {
      this.isAddFlag = val;
      this.ruleFormAdd = {};
      this.formconfigAdd[0].list = attrChange2(this.userProject.projectList,'projectCode','projectName');
      this.publiconfigAdd.show = true;
    },

    /*新建保存*/
    saveBtn(val) {
      this.clickedBtn = val;
      this.$refs.form.submitForm()
    },

    saveForm(val) {
      console.log(val)
      let {contractTerm} = val;
      const _contractTerm = contractTerm && contractTerm.length ? contractTerm : []
      let s=` 00:00:00`
      let d=` 23:59:59`
      if(_contractTerm.length>0){
        _contractTerm[0]= `${_contractTerm[0]}${s}`
        _contractTerm[1]= `${_contractTerm[1]}${d}`
      }
      let {paymentTime} = val;
      const _paymentTime = paymentTime && paymentTime.length ? paymentTime : []
      let {annualCost,borrower,city,deposit,dormitoryItems,houseAddress,
        housePersonnel,houseType,monthlyRent,otherFee,paymentCycle,
        pm,principal,projectCode,projectName} = val;
      let postParam = {
        annualCost,borrower,city,deposit,dormitoryItems,houseAddress,
        housePersonnel,houseType,monthlyRent,otherFee,paymentCycle,
        pm,principal,projectCode,projectName,
        "contractEndDate": _contractTerm[1] || '',
        "contractStartDate": _contractTerm[0] || '',
        "employeeNumber": this.getUserNum(),
        "paymentTime": `${_paymentTime[0]}~${_paymentTime[1]}` || '',
        "rentCode":Math.random()*1000+'',
        "status": 0,
      };
      this.$http.post(`${COMMON_API_PATH}/rentAccount/addRentAccount`, postParam)
        .then(response => {
          if (response.data.statusCode == 1) {
            if(this.clickedBtn == 'save'){
              this.$message({
                message: '添加成功',
                type: 'success'
              });
              this.publiconfigAdd.show = false;
              this.getTableDatas();
            }else if(this.clickedBtn == 'submit'){
              this.$http.post(`${COMMON_API_PATH}/rentAccount/submitRentAccount`,[postParam.rentCode])
                .then((res) => {
                  if(res.data.statusCode == 1){
                    this.$message({
                      message: '提交成功',
                      type: 'success'
                    });
                    this.publiconfigAdd.show = false;
                    this.getTableDatas();
                  }

                }).catch((error) => {

              })

            }

          }

        })
        .catch(error => {
        })
    },

    //修改保存
    saveBtnEdit(val){
      this.clickedBtn = val;
      this.$refs.form2.submitForm();
    },

    saveForm2(val) {
      console.log(val);
      let {contractTerm} = val;
      const _contractTerm = contractTerm && contractTerm.length ? contractTerm : []
      let s=` 00:00:00`
      let d=` 23:59:59`
      if(_contractTerm.length>0){
        _contractTerm[0]= `${_contractTerm[0]}${s}`
        _contractTerm[1]= `${_contractTerm[1]}${d}`
      }
      let {paymentTime} = val;
      const _paymentTime = paymentTime && paymentTime.length ? paymentTime : []
      let {annualCost,borrower,city,deposit,dormitoryItems,houseAddress,
        housePersonnel,houseType,monthlyRent,otherFee,paymentCycle,
        pm,principal,projectCode,projectName,rentCode,status,employeeNumber} = val;
      let postParam = {
        annualCost,borrower,city,deposit,dormitoryItems,houseAddress,
        housePersonnel,houseType,monthlyRent,otherFee,paymentCycle,
        pm,principal,projectCode,projectName,rentCode,status,employeeNumber,
        "contractEndDate": _contractTerm[1] || '',
        "contractStartDate": _contractTerm[0] || '',
        "paymentTime": `${_paymentTime[0]}~${_paymentTime[1]}` || '',
      };
      this.$http.post(`${COMMON_API_PATH}/rentAccount/updateRentAccount`, this.ruleFormEdit)
        .then(response => {
          if (response.data.statusCode == 1) {
            if(this.clickedBtn == 'edit'){
              this.$message({
                message: '修改成功',
                type: 'success'
              });
              this.publiconfigEdit.show = false;
              this.getTableDatas();
            }else if(this.clickedBtn == 'submit'){
              this.$http.post(`${COMMON_API_PATH}/rentAccount/submitRentAccount`,[postParam.rentCode])
                .then((res) => {
                  if(res.data.statusCode == 1){
                    this.$message({
                      message: '提交成功',
                      type: 'success'
                    });
                    this.publiconfigEdit.show = false;
                    this.getTableDatas();
                  }

                }).catch((error) => {

              })

            }

          }

        })
        .catch(error => {
        })
    },

    // 编辑
    editBtn(val) {
      //  只有保存的和驳回的可编辑
      let self = this;
      self.isAddFlag = val;
      let count = self.multipleSelection.length;
      if (count !== 1) {
        return self.$message({
          message: '请选择一项进行修改',
          type: 'warning',
        })
      }
      console.log(self.multipleSelection[0])
      if (self.multipleSelection[0].status!==0 && self.multipleSelection[0].status !== 2) {
        return self.$message({
          message: '审批中的单据不能修改',
          type: 'warning',
        })
      }
      this.selectId = self.multipleSelection[0].rentCode;
      this.formconfigEdit[0].list = attrChange2(this.userProject.projectList,'projectCode','projectName');
      this.checkRenting(this.selectId);
      this.publiconfigEdit.show = true;
    },

    handelRenting(val) {
      this.publiconfigEdit.show = true;
      this.publiconfigEdit.title = "查看租房单";
      this.formconfigEdit.forEach((item, index) => {
        this.$set(item, 'disabled', true);
      });
      this.checkRenting(val)
    },
    //查看详情
    checkRenting(param) {
      this.$http
        .post(`${COMMON_API_PATH}/rentAccount/queryByCode`, param)
        .then(function (res) {
          console.log("查看详情");
          if(res.data.statusCode == 1){
            let item = res.data.item;
            this.$set(this.ruleFormEdit, 'annualCost', item.annualCost);
            this.$set(this.ruleFormEdit, 'borrower', item.borrower);
            this.$set(this.ruleFormEdit, 'city', item.city);
            this.$set(this.ruleFormEdit, 'deposit', item.deposit);
            this.$set(this.ruleFormEdit, 'dormitoryItems', item.dormitoryItems);
            this.$set(this.ruleFormEdit, 'houseAddress', item.houseAddress);
            this.$set(this.ruleFormEdit, 'housePersonnel', item.housePersonnel);
            this.$set(this.ruleFormEdit, 'houseType', item.houseType);
            this.$set(this.ruleFormEdit, 'monthlyRent', item.monthlyRent);
            this.$set(this.ruleFormEdit, 'otherFee', item.otherFee);
            this.$set(this.ruleFormEdit, 'paymentCycle', item.paymentCycle);
            this.$set(this.ruleFormEdit, 'pm', item.pm);
            this.$set(this.ruleFormEdit, 'principal', item.principal);
            this.$set(this.ruleFormEdit, 'projectCode', item.projectCode);
            this.$set(this.ruleFormEdit, 'projectName', item.projectName);
            this.$set(this.ruleFormEdit, 'contractStartDate', item.contractStartDate);
            this.$set(this.ruleFormEdit, 'contractEndDate', item.contractEndDate);
            this.$set(this.ruleFormEdit, 'contractTerm', [item.contractStartDate,item.contractEndDate]);
            this.$set(this.ruleFormEdit, 'employeeNumber', item.employeeNumber);
            this.$set(this.ruleFormEdit, 'paymentTime', item.paymentTime.split('~'));
            this.$set(this.ruleFormEdit, 'status', item.status);
            this.$set(this.ruleFormEdit, 'rentCode', item.rentCode);
          }
        });
    },

    // 删除
    delBtn() {
      let self = this;
      let count = self.multipleSelection.length;
      if (count == 0) {
        return self.$message({
          message: '请勾选您要删除的选项',
          type: 'warning',
        })
      }
      let ids = []
      self.multipleSelection.forEach((item, index) => {
        if (item.status ==2 || item.status == 0) {
          ids.push(item.rentCode)
        } else {
          return self.$message({
            message: '已提交的单据不能删除',
            type: 'warning',
          })
        }
      })
      if (ids.length == 0) return;
      let params = ids
      this.$confirm('此操作将删除该请假单, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        center: true
      }).then(() => {
        this.sureDel(params)
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },

    sureDel(params) {
      this.$http.post(`${COMMON_API_PATH}/rentAccount/deleteRentAccount`, params)
        .then(function (res) {
          // console.log(res)
          if (res.data.statusCode == 1) {
            this.$message({
              message: '删除成功',
              type: 'success'
            });
            this.getTableDatas();
          } else {
            this.$message({
              message: '删除失败' + res.data.massage,
              type: 'error'
            });
          }

        });
    },

    // 提交
    submitBtn() {
      let self = this
      let count = self.multipleSelection.length;
      if (count == 0) {
        return self.$message({
          message: '请勾选您要提交的选项',
          type: 'warning',
        })
      };
      let ids = []
      for(let  i=0;i< self.multipleSelection.length;i++) {
        let item = self.multipleSelection[i]
        if (item.status !== 0 && item.status !== 2) {
          return this.$message({
            message: '已提交的不能修改',
            type: 'warning'
          });
        }
        if (item.status==2) {
          return this.$message({
            message: '驳回的请先修改再提交',
            type: 'warning'
          });
        }
        ids.push(item.rentCode);
      }
      if (ids.length == 0) return
      let params = ids
      this.$http
        .post(`${COMMON_API_PATH}/rentAccount/submitRentAccount`, params)
        .then(function (res) {
          if (res.data.statusCode == 1) {
            this.$message({
              message: '提交成功',
              type: 'success'
            });
            this.getTableDatas();
            this.$refs.multipleTable.clearSelection()

          } else {
            this.$message({
              message: res.data.massage,
              type: 'error'
            });
          }
        });
    },

    handleSelectionChange(val) {
      this.multipleSelection = val;
    },

    //查看审批历史
    handelCheck(val){
      this.publiconfigCheck.show=true
      let params={
        payBackCode:val
      };
      this.$http
        .post(`${COMMON_API_PATH}/payBackRecord/getDetailsApproval`, params)
        .then((res) => {
          this.dataTable2.data=res.data.item;
        });
    }
  }
}
</script>
<style scoped>
.loanAll {
  padding: 20px;
}

.btn {
  background: #36618a;
  color: #fff;
}
</style>